package org.chuan.hisports.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

//本工具为了创建当前时间，以便会员名生成与时间添加
public class CreatTime {
    //获取当前时间
    public LocalDateTime creatTime(){
        LocalDateTime localDateTime = LocalDateTime.now();

        return localDateTime;
    }

    //修改时间格式为用户名所需的时间
    public String userTime(LocalDateTime localDateTime){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddhhmmss");
        String newtime = formatter.format(localDateTime);
        return newtime;
    }


    //修改时间格式为数据库所需的时间
    public String dataTime(LocalDateTime localDateTime){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
        String newtime = formatter.format(localDateTime);
        return newtime;
    }

    //将数据库获得的String的时间类型改变为LocalDateTime时间类型
    public LocalDateTime dateTime(String oldTime){

        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime newTime = LocalDateTime.parse(oldTime, dtf);
        return newTime;
    }
}
